﻿<!DOCTYPE html>
<!--部门职务编辑-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <script src="../static/js/Resource/RisksManagement.js"></script>
    <script src="../static/js/Mock/RisksManagement.js"></script>
    <style>
        /*说明：
         由于mystyle.css中162行.el-form-item__content {line-height: normal!important;}导致的
         index.css中.el-form-item--mini .el-form-item__content, .el-form-item--mini .el-form-item__label{    line-height: 28px;}失效
         但出于无法修改样式表的情况，所以在该页面添加以下样式，以保证页面内标题和内容不偏离
        */
        .el-form-item--mini .el-form-item__content,
        .el-form-item--mini .el-form-item__label {
            line-height: 28px !important;
        }
    </style>
    <style>

        .el-input__suffix {
            /* z-index: 9; */
        }
    </style>

</head>
<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini" label-position="right">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item :label="SysDepartment.Name+mark.m">
                            {{Form.name}}
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item :label="SysDepartment.CreateFactory+mark.m">
                                {{getFactoryValue(Form.createFactory)}}
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="24">
                    <el-form-item :label="'选择职务'+mark.m" prop="Remarks" class="inputTextarea">
                        <template>
                            <el-checkbox-group v-model="dutyChecked">
                                <el-checkbox v-for="v in duties" :label="v.id.toLowerCase()">{{v.name}}</el-checkbox>
                            </el-checkbox-group>
                        </template>
                    </el-form-item>
                </el-col>
            </el-row>



            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button>
                    <!-- <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button> -->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                //业务表单内容
                Form: {
                    id: '',
                    name: '',
                    createFactory: null,
                    sysDepartmentDuties: null
                },
                factory: [],
                duties: [],
                dutyChecked: [],
                //表单验证
                rules: {

                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            var form = {
                                SysDepartmentID: mythis.id,
                                SysDutyIDs:[]
                            };
                            console.log(form)
                            if (mythis.dutyChecked) {
                                mythis.dutyChecked.forEach(function (v) {
                                    form.SysDutyIDs.push(v)
                                })
                            }
                            console.log(form)
                            //onSubmitForm(mythis, '/api/SysDepartment/SaveDuty', form);
                            myAjax("post", mythis, '/api/SysDepartment/SaveDuty', form, function (response) {
                                console.log('response', response)


                                showMessage(msg.OperatingOk, 'success');
                                parent.app.ListItem.dialogVisible = false;
                            });
                        } else {
                            //验证失败
                            return false;
                        }
                    });

                },
                getData: function () {
                    getData(this, '/api/SysDepartment/Get?id=' + this.id);
                    //var mythis = this;
                    //if (mythis.id != null && mythis.id != '') {
                    //    myAjax("get", mythis, '/api/SysDepartment/Get?id=' + mythis.id, null, function (response) {
                    //        console.log('response', response)
                    //        var ajaxModel = response.data;
                    //        mythis.Form = ajaxModel;
                    //        //mythis.userFrom.sex = mythis.userFrom.sex + "";
                    //    },false);
                    //}
                },
                //初始化职务数据
                getDuties: function () {
                    var currObj = this;
                    myAjax("post", currObj, '/api/SysDuty/GetList', {
                        model: {
                            "name": "",
                            "createFactory": ""
                        },
                        offset: 0,
                        limit: 100
                    }, function (response) {
                        currObj.duties = response.data.pageData

                    });
                },
                //工厂id to value
                getFactoryValue: function (key) {
                    if (!key) return '';
                    var data = this.factory;
                    var val = key;
                    if (data.length > 0) {
                        data.forEach(function (o, j) {
                            if (o.key == key) {
                                val = o.value;
                                return;
                            }
                        });
                    }
                    return val;
                }

            },
            mounted: function () {
                //初始化工厂数据
                this.factory = getDicData(['9001'])
                //初始化职务
                this.getDuties();
                this.id = getUrlParam("id");
                this.Form.id = this.id;
                this.getData();

                //初始化选中项
                if (this.Form.sysDepartmentDuties) {
                    var mythis = this;
                    this.Form.sysDepartmentDuties.forEach(function (v) {
           
                        mythis.dutyChecked.push(v.sysDuty.id.toLowerCase());
                    })
                }

            }
        });

    </script>
</body>

</html>